<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>正则表达式测试工具</title>
    <link rel="stylesheet" href="../../bootstrap/bootstrap.min.css">
    <style>
        .result {
            padding: 10px;
            margin-top: 20px;
            background-color: #f8f9fa;
            border-radius: 5px;
        }
    </style>
</head>

<body>
    <div class="container mt-5">
        <h1 class="mb-4">正则表达式测试工具</h1>
        <form class="mb-3">
            <div class="form-floating">
                <input type="text" class="form-control" placeholder="请输入正则表达式" id="regexInput">
                <label for="regexInput">请输入正则表达式</label>
            </div>
            <div class="form-floating mt-3">
                <textarea class="form-control" placeholder="请输入要测试的字符串" id="textInput" style="height: 150px"></textarea>
                <label for="textInput">请输入要测试的字符串</label>
            </div>
        </form>
        <button type="button" class="btn btn-primary" onclick="testRegex()">测试</button>
        <div class="result mt-4">
            <p><strong>匹配结果：</strong></p>
            <div id="matchResult"></div>
        </div>
    </div>
    <script>
        function testRegex() {
            // 获取输入的正则表达式和要测试的字符串
            const regex = new RegExp(regexInput.value);
            const text = textInput.value;

            // 在匹配结果输出前先清空输出区域
            matchResult.innerHTML = '';
            // 匹配字符串并输出结果
            const matches = text.match(regex);
            if (matches) {
                matches.forEach(match => {
                    const div = document.createElement("div");
                    div.textContent = match;
                    matchResult.appendChild(div);
                });
            } else {
                matchResult.innerHTML = "未匹配到任何内容";
            }
        }
    </script>
</body>

</html>